<?php defined('BASEPATH') OR exit('No direct script access allowed');
/**
 * Description: 列表
 *
 * @author      Eden
 * @datetime    2016/12/9 00:43
 * @copyright   Beijing CmsTop Technology Co.,Ltd.
 */
class Adv_Model extends API_Model
{

    /**
     * 初始化
     */
    public function __construct()
    {
        parent::__construct();
    }

    public function run(Array $params)
    {
        $types = [
            '1' => 'link',
            '2' => 'base',
            '3' => 'product'
        ];

        $send['state'] = false;
        do {
            try {
                $db = clone($this->db);
                $query = $db->get_where('bbs_slider', ['status' => 1]);
                $rows = $query->result_array();
                $return = [];
                if (!empty($rows)) foreach ($rows as $item) {
                    $return[] = [
                        'title' => $item['title'],
                        'source' => $item['source'],
                        'thumb' => thumb($item['thumb'], 645, 215),
                        'type' => $types[$item['type']],
                        'value' => $item['value']
                    ];
                }
                $send['state'] = true;
                $send['data'] = $return;
            } catch (Exception $e) {
                $send['error'] = '广告获取失败';
            }
        } while(false);
        $this->output->send($send);
    }
}
